package com.rainng.coursesystem.controller.admin;

import com.rainng.coursesystem.config.themis.annotation.Admin;
import com.rainng.coursesystem.controller.BaseController;
import com.rainng.coursesystem.controller.admin.vo.SysGroupReqDTO;
import com.rainng.coursesystem.controller.admin.vo.SysUserQueryReqDTO;
import com.rainng.coursesystem.controller.admin.vo.SysUserSaveReqDTO;
import com.rainng.coursesystem.model.entity.AdminEntity;
import com.rainng.coursesystem.model.vo.response.ResultVO;
import com.rainng.coursesystem.module.system.dto.response.SysUserBaseResDTO;
import com.rainng.coursesystem.service.admin.AdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


//@Admin(Admin.ADMIN_MANAGE)
@Api(tags = "权限接口")
@RequestMapping("/admin/admin")
@RestController
public class AdminController extends BaseController {
    private final AdminService service;

    public AdminController(AdminService service) {
        this.service = service;
    }

//    @GetMapping("/test")
//    public Object get() {
//        return "绕过鉴权";
//    }

    @GetMapping("/{id}")
    public ResultVO get(@PathVariable Integer id) {
        return service.get(id);
    }

    @PostMapping
    public ResultVO create(@RequestBody @Validated AdminEntity entity) {
        return service.create(entity);
    }


    @PostMapping("/{id}")
    public ResultVO delete(@PathVariable Integer id) {
        return service.delete(id);
    }

    @ApiOperation(value = "用户管理:增改", notes = "对齐原有逻辑")
    @PostMapping("/v2/user/save")
    public ResultVO createObj(@RequestBody SysUserSaveReqDTO entity) {
        return service.createUser(entity);
    }

    @ApiOperation(value = "用户管理:根据主键单删", notes = "")
    @PostMapping("/v2/user/delete/{id}")
    public ResultVO deleteObj(@PathVariable String id) {
        return service.deleteUser(id);
    }

    @ApiOperation(value = "用户管理:展示接口", notes = "对齐原有")
    @PostMapping("/v2/user/page")
    public ResultVO getList(@RequestBody SysUserQueryReqDTO vo) {
        return service.showList(vo);
    }

    @ApiOperation(value = "用户管理:展示接口返回total", notes = "返回total")
    @PostMapping("/v2/user/page/count")
    public ResultVO getTotal(@RequestBody SysUserQueryReqDTO vo) {
        return service.getTotal(vo);
    }

    @ApiOperation(value = "用户管理:根据主键批量删", notes = "")
    @PostMapping("/v2/user/delete")
    public ResultVO deleteMultiObj(@RequestBody List<String> ids) {
        return service.deleteMultiUser(ids);
    }

    @ApiOperation(value = "用户管理:detail接口", notes = "")
    @GetMapping("/v2/user/detail/{id}")
    public ResultVO getDetail(@PathVariable String id) {
        return service.getListById(id);
    }

    @GetMapping("/v2/user/byrole")
    public ResultVO getUserByRole(){
        return service.getUserByRoleId();
    }


    @PutMapping
    public ResultVO update(@RequestBody @Validated AdminEntity entity) {
        return service.update(entity);
    }

    @GetMapping()
    public ResultVO list() {
        return service.list();
    }


    //角色展示接口
    @ApiOperation(value = "角色管理", notes = "返回所有")
    @GetMapping("/v2/role")
    public ResultVO showUserRoles() {
        return service.getAllRoles();
    }


    //分组
    @ApiOperation(value = "组别:查询", notes = "返回所有")
    @GetMapping("/v2/group")
    public ResultVO showAllGroups() {
        return service.getAllGroups();
    }

    //分组
    @ApiOperation(value = "组别:查询", notes = "带条件查询")
    @PostMapping("/v2/group/page")
    public ResultVO showGroups(@RequestBody SysGroupReqDTO req) {
        return service.getGroups(req);
    }

    @ApiOperation(value = "组别:查询返回总页数", notes = "返回所有")
    @PostMapping("/v2/group/page/count")
    public ResultVO showGroupsCount(@RequestBody SysGroupReqDTO req) {
        return service.getGroupsCount(req);
    }

    @ApiOperation(value = "组别:detail", notes = "返回所有")
    @GetMapping("/v2/group/detail/{id}")
    public ResultVO showGroupsDetail(@PathVariable String id) {
        return service.getGroupById(id);
    }

    @ApiOperation(value = "组别:增改", notes = "返回所有")
    @PostMapping("/v2/group/save")
    public ResultVO saveGroup(@RequestBody SysGroupReqDTO input) {
        return service.saveGroup(input);
    }

    @ApiOperation(value = "组别:删除", notes = "返回所有")
    @PostMapping("/v2/group")
    public ResultVO deleteGroups(@RequestBody List<String> ids) {
        return service.deleteGroups(ids);
    }
}
